PROJECT(znx)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

# ADD_DEFINITIONS(-DZNX_MEM_NO_POOL)
# ADD_DEFINITIONS(-DZNX_THREAD_MEM_NO_POOL)
# ADD_DEFINITIONS(-DZNX_POOL_NO_PAGE)
ADD_DEFINITIONS(-DZNX_SSL_ASYNC)

SET(CMAKE_C_COMPILER "clang-11")

SET(C_FLAGS
    -Wall
    -Wextra
    -Werror
    -Wno-unused-parameter
    -Wconversion
    -march=native
    -std=gnu11
    -ggdb
    -fstack-protector
    --param=ssp-buffer-size=4
)


IF(BUILD_TYPE STREQUAL "release")
    STRING(PREPEND C_FLAGS
        "-O2;"
    )

ELSEIF(BUILD_TYPE STREQUAL "debug")
    STRING(PREPEND C_FLAGS
        "-O0;"
    )

ELSE()
    STRING(PREPEND C_FLAGS
        "-fsanitize=address;"
        "-fno-omit-frame-pointer;"
        "-O0;"
    )
ENDIF()

STRING(REPLACE ";" " " CMAKE_C_FLAGS "${C_FLAGS}")
MESSAGE(C_FLAGS ": " ${CMAKE_C_FLAGS})

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/output/libs/openssl/include/openssl)
MESSAGE(${PROJECT_SOURCE_DIR}/output/libs/openssl/include/openssl)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src)

LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/output/libs/openssl/lib)

ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(test)
